package com.example.Ademo;

import java.sql.*;

/**
 * @version: java version 23
 * @Author: 韩学新
 * @description:
 * @date: 2025-05-17 下午4:49
 */
public class JdbcDemo1 {
    public static void main() throws ClassNotFoundException, SQLException {

        //1.引入mysql驱动
        /*
         * <dependency>
         *             <groupId>mysql</groupId>
         *             <artifactId>mysql-connector-java</artifactId>
         *             <version>8.0.28</version>
         *         </dependency>
         */

        //2.注册mysql驱动  反射机制
//        Class.forName("com.mysql.jdbc.Driver");

        //3.创建数据库连接
//        Connection connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/java", "root", "123456");

        //4.获取执行者对象
//        Statement statement = connection.createStatement();
//
//        //5.执行sql语句
//        ResultSet resultSet = statement.executeQuery("select * from student");
//
//        //6.判断是否存在 下一行
//        while (resultSet.next()) {
//            int id = resultSet.getInt("id");
//            String name = resultSet.getString("name");
//            int age = resultSet.getInt("age");
//            System.out.println("id: " + id + ", name: " + name + ", age: " + age);
//        }
//        //7.关闭资源
//        connection.close();
//        statement.close();
    }
}
